<?php

$data = $_POST;

$preg = "/^[a-z][a-z0-9_]{5,10}$/";

$c = preg_match($preg,$data['nickname']);

if(!$c){
	exit(json_encode(['error'=>1,'info'=>'用户名必须是由字母数字6-8位组成，字母开头']));
}

$oldArr = file_get_contents("./data/user.txt");

$oldArr = json_decode($oldArr,true);

foreach ($oldArr as  $user) {
	if($user['nickname']==$data['nickname']){
		exit(json_encode(['error'=>1,'info'=>'用户名已存在']));
	}
}

exit(json_encode(['error'=>0,'info'=>'用户可用']));
